package networkDownload;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;

public class MyTread extends Thread{
	private int length;
	private int seek;
	private RandomAccessFile df;
	private RandomAccessFile dp;
	
	public MyTread(int length,int seek) throws IOException{
		this.length = length;
		this.seek = seek;
		this.df = new RandomAccessFile("filePool/1.txt","r");
		this.dp = new RandomAccessFile("filePool/2.txt","rw");
		dp.seek(seek);
		df.seek(seek);
	}
	
	@Override
	public void run() {
		byte[] buf = new byte[2];
		
		int m = 0;
		try {
			int downloadsize = 0;
			
			while((m = df.read(buf)) != -1){
				downloadsize += m;
				if((length - downloadsize) <= buf.length){
					dp.write(buf, 0, length - downloadsize);           //这里判断是否到了截止的断点、
					break;
				}
				dp.write(buf, 0, m);
			}
			df.close();
			dp.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
